package com.example.test.controller;

import com.example.test.Bean.UserBean;
import com.example.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    UserService userservice;

    @RequestMapping("users")
    public String showUser(ModelMap modelmap){
        List<UserBean> allUser = userservice.getAllUser();
        modelmap.put("userlist",allUser);
        return "users";
    }

    @RequestMapping("addUser")
    @ResponseBody
    public Map addUser(UserBean userBean){
        Map<String,Object> map = new HashMap<String,Object>();
            int flag = userservice.insertUser(userBean);
            if(flag == 1){
                map.put("msg","增加用户成功！");
                return map;
            }else{
                map.put("msg","增加用户失败！");
                return map;
            }
    }
}
